window.onload = function () {
	hideMenu();
    showSubMenu(document.getElementById('active'));
    prepareLinks(document.getElementById('menu').childNodes);
    openExtLink();
    prepareForm();
};


/* menu managment */
function hideMenuNodes(nodes) {
    for (var i = 1; i < nodes.length; i++) {
        if (nodes[i].nodeName == "DIV") {
            nodes[i].style.display = "none";
            if (nodes[i].hasChildNodes)
                hideMenuNodes(nodes[i].childNodes);
        }
    }
}

function hideMenu() {
    var div_root = document.getElementById("menu");
    if(!div_root)
        return false;
    var nodes = div_root.childNodes;
    for (var i = 0; i < nodes.length; i++) 
        if (nodes[i].nodeName == "DIV")
            hideMenuNodes(nodes[i].childNodes);
    
    return true;
}

function showSubMenu(link) {
	    var nodes = link.parentNode.parentNode.childNodes;
	    for (var i = 1; i < nodes.length; i++)
	        if (nodes[i].nodeName == "DIV")
	        	if (nodes[i].style.display == "none")
		            nodes[i].style.display = "block";
	        	else
	        		nodes[i].style.display = "none";
	    var open = document.getElementById('open');
	    if (open) {
	    	open.setAttribute('id','');
	        showSubMenu(open.parentNode);
	    }
}

function prepareLinks(nodes) {
	for (var i = 0; i < nodes.length; i++) {
        if (nodes[i].nodeName == 'A' && nodes[i].href.charAt(nodes[i].href.length - 1) == "#") {
            nodes[i].onclick = function() {
                showSubMenu(this);
                return false;
            };
        }
        if (nodes[i].hasChildNodes)
            prepareLinks(nodes[i].childNodes);
    }
}


/* external links */
function openExtLink() {
    var links = document.getElementsByTagName('A');
    for (var i = 0; i < links.length; i++) {
        if (links[i].type == 'extLink') {
            links[i].onclick = function() {
                window.open(this.href);
                return false;
            };
        }
    }
}


/* form managment */
function prepareForm() {
    if (!document.forms[0])
        return;
        
    document.forms[0].onsubmit = function() {
        return checkData();
    };
}

function checkData() {
    return true;
}


/* Scrolling images */
var imgPath = new Array;
var i = 0;

function startSlideShow(images) {
	imgPath = images;
	scroll();
}

function scroll() {
	if (i > imgPath.length - 1)
		i = 0;

	document.getElementById("scrollImg").src = imgPath[i++];
	setTimeout("scroll()", 1500);
}
